#function(idata)
// 查看方向图曲线

#import toolbox

local tb = toolbox.new_smartdata(idata);
tb.title = _hT("ViewData");
tb.window = "toolbox.frame";

local add_param_phi = function(op)
{
    op.add_param(
        table {
            name  : "phi0";
            type  : "string";
            label : _dT("Phi.start");
            value : "-180";
            unit  : "DEG";
            limit : nil;
            delay : 0
        }
    );

    op.add_param(
        table {
            name  : "phi1";
            type  : "string";
            label : _dT("Phi.stop");
            value : "180";
            unit  : "DEG";
            limit : nil;
            delay : 0
        }
    );

    op.add_param(
        table {
            name  : "nphi";
            type  : "string";
            label : _dT("Phi.num");
            value : "361";
            limit : nil;
            delay : 0
        }
    );
};

local make_executor = function(func)
{
    return function(idata, pdata)
    {
        local gg = fig.new_figure();
        
        local phi0 = eval1(pdata.phi0);
        local phi1 = eval1(pdata.phi1);
        local nphi = eval1(pdata.nphi);

        local phi = linspace(phi0, phi1, nphi);
        local gain = math.dB(func(phi));

        fig.polar_deg(phi, gain);
        fig.axis_rmin(min(gain));

        return gg;
    };
};


// 发射机增益图
local op = tb.add_operation(_hT("Tx Gain"));
op.autoexec = true;
add_param_phi(op);
op.do_execute = make_executor(idata.TxFunc);

op = tb.add_operation(_hT("Rx Gain"));
op.autoexec = true;
add_param_phi(op);
op.do_execute = make_executor(idata.RxFunc);

return tb;